/**
 *
 */
package com.yangtao.prototype.system.domain;

import com.yangtao.framework.hibernate.BaseEntity;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 用户角色类
 *
 * @author 杨涛
 */
@Entity
@Table(name = "sys_role")
public class Role extends BaseEntity implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 角色代码
	 */
	@Column(length = 20)
	private String roleCode;
	/**
	 * 角色名称
	 */
	@Column(length = 200)
	private String roleName;
	/**
	 * 角色类型
	 */
	@Column(length = 20)
	private String roleType;
	/**
	 * 是否启用
	 */
	@Column(length = 1)
	private Boolean active;

	/**
	 * 组织机构Id，不能更新，不能修改，仅仅为查询使用
	 */
	@Column(insertable = false, updatable = false)
	private String organizationId;

	/**
	 * 所属组织机构
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "organizationId")
	private Organization organization;
	/**
	 * 角色和用户角色表之间的关系配置，一对多，由用户角色表来维护他们之间的关系
	 */
	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
	private List<UserRole> users;
	/**
	 * 角色和权限之间的关系，角色和权限是一对多的关系，关系由关联表来维护
	 */
	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.ALL})
	private List<FunctionAuthority> functionAuthorize;
	/**
	 * 页面元素权限
	 */
	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.ALL})
	private List<PageElementAuth> pageElementAuthorize;

	public List<PageElementAuth> getPageElementAuthorize() {
		return pageElementAuthorize;
	}

	public void setPageElementAuthorize(List<PageElementAuth> pageElementAuthorize) {
		this.pageElementAuthorize = pageElementAuthorize;
	}

	public String getRoleCode() {
		return roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	/**
	 * @return the roleName
	 */
	public String getRoleName() {
		return roleName;
	}

	/**
	 * @param roleName the roleName to set
	 */
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	/**
	 * @return the roleType
	 */
	public String getRoleType() {
		return roleType;
	}

	/**
	 * @param roleType the roleType to set
	 */
	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

	/**
	 * @return the users
	 */
	public List<UserRole> getUsers() {
		return users;
	}

	/**
	 * @param users the users to set
	 */
	public void setUsers(List<UserRole> users) {
		this.users = users;
	}

	public List<FunctionAuthority> getFunctionAuthorize() {
		return functionAuthorize;
	}

	public void setFunctionAuthorize(List<FunctionAuthority> functionAuthorize) {
		this.functionAuthorize = functionAuthorize;
	}

	public Organization getOrgnize() {
		return organization;
	}

	public void setOrgnize(Organization organization) {
		this.organization = organization;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	/**
	 * @return the organization
	 */
	public Organization getOrganization() {
		return organization;
	}

	/**
	 * @param organization the organization to set
	 */
	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public String getOrganizationId() {
		return organizationId;
	}

	public void setOrganizationId(String organizationId) {
		this.organizationId = organizationId;
	}
}
